
R version 2.5.1 (2007-06-27)
Copyright (C) 2007 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(foreign)
> library(mvtnorm)
Warning message:
package 'mvtnorm' was built under R version 2.8.0 
> library(sfsmisc)
Warning message:
package 'sfsmisc' was built under R version 2.8.0 
> library(polycor)
Warning message:
package 'polycor' was built under R version 2.8.0 
> x <- read.spss("example33.sav")
> p1 <- as.factor(x$PTCI1)
> p2 <- as.factor(x$PTCI2)
> p3 <- as.factor(x$PTCI3)
> p4 <- as.factor(x$PTCI4)
> p5 <- as.factor(x$PTCI5)
> p6 <- as.factor(x$PTCI6)
> res <- hetcor(p1, p2, p3, p4, p5, p6, ML=FALSE, std.err=FALSE)
> res$correlation
          p1        p2        p3        p4        p5        p6
p1 1.0000000 0.2552982 0.2872673 0.3018098 0.1548009 0.2285831
p2 0.2552982 1.0000000 0.5547007 0.4294489 0.4987368 0.4629436
p3 0.2872673 0.5547007 1.0000000 0.5078735 0.5131349 0.4096333
p4 0.3018098 0.4294489 0.5078735 1.0000000 0.5615683 0.4436757
p5 0.1548009 0.4987368 0.5131349 0.5615683 1.0000000 0.5490700
p6 0.2285831 0.4629436 0.4096333 0.4436757 0.5490700 1.0000000
> res$type
     [,1]         [,2]         [,3]         [,4]         [,5]        
[1,] ""           "Polychoric" "Polychoric" "Polychoric" "Polychoric"
[2,] "Polychoric" ""           "Polychoric" "Polychoric" "Polychoric"
[3,] "Polychoric" "Polychoric" ""           "Polychoric" "Polychoric"
[4,] "Polychoric" "Polychoric" "Polychoric" ""           "Polychoric"
[5,] "Polychoric" "Polychoric" "Polychoric" "Polychoric" ""          
[6,] "Polychoric" "Polychoric" "Polychoric" "Polychoric" "Polychoric"
     [,6]        
[1,] "Polychoric"
[2,] "Polychoric"
[3,] "Polychoric"
[4,] "Polychoric"
[5,] "Polychoric"
[6,] ""  
> library(psych)
> KMO(res$correlation)
Kaiser-Meyer-Olkin factor adequacy
Call: KMO(r = res$correlation)
Overall MSA =  0.81
MSA for each item = 
  p1   p2   p3   p4   p5   p6 
0.84 0.85 0.83 0.83 0.78 0.77         
> res$correlation[upper.tri(res$correlation)] <- 0
> res1 <- factanal(covmat=res$correlation, factors=3, rotation="varimax")
> res2 <- factanal(covmat=res$correlation, factors=3, rotation="promax")
> res2 <- factanal(covmat=res$correlation, factors=3, rotation="none")
> res3 <- princomp(covmat=res$correlation)

> res1

Call:
factanal(factors = 3, covmat = res$correlation, rotation = "varimax")

Uniquenesses:
   p1    p2    p3    p4    p5    p6 
0.773 0.005 0.505 0.439 0.005 0.608 

Loadings:
   Factor1 Factor2 Factor3
p1         0.121   0.457  
p2 0.267   0.919   0.280  
p3 0.377   0.347   0.483  
p4 0.454   0.160   0.574  
p5 0.961   0.216   0.158  
p6 0.456   0.270   0.333  

               Factor1 Factor2 Factor3
SS loadings      1.554   1.125   0.986
Proportion Var   0.259   0.188   0.164
Cumulative Var   0.259   0.447   0.611

The degrees of freedom for the model is 0 and the fit was 0.0017 
> res2

Call:
factanal(factors = 3, covmat = res$correlation, rotation = "none")

Uniquenesses:
   p1    p2    p3    p4    p5    p6 
0.773 0.005 0.505 0.439 0.005 0.608 

Loadings:
   Factor1 Factor2 Factor3
p1  0.239  -0.101   0.400 
p2  0.864  -0.499         
p3  0.619           0.332 
p4  0.576   0.133   0.461 
p5  0.865   0.497         
p6  0.586           0.201 

               Factor1 Factor2 Factor3
SS loadings      2.609   0.533   0.523
Proportion Var   0.435   0.089   0.087
Cumulative Var   0.435   0.524   0.611

The degrees of freedom for the model is 0 and the fit was 0.0017 
> res3
Call:
princomp(covmat = res$correlation)

Standard deviations:
   Comp.1    Comp.2    Comp.3    Comp.4    Comp.5    Comp.6 
1.7654030 0.9463959 0.7863708 0.7601601 0.6426435 0.6152023 

 6  variables and  NA observations.
> 

> 
> # PW NOTE: SOME MISSING LOADINGS; THE MISSINGNESS PATTERN DEPENDS ON WHICH OF THE TWO ROTATIONS IS USED;
> 
> library(sem)
Warning message:
package 'sem' was built under R version 2.9.0 
> model.f1<-matrix(c(    'F1->p1', 'lam1',NA,
+                        'F1->p2', 'lam2',NA,
+                        'F1->p3', 'lam3',NA,
+                        'F1->p4', 'lam4',NA,
+                        'F1->p5', 'lam5',NA,
+                        'F1->p6', 'lam6',NA,
+                       'p1<->p1', 'th1' ,NA,
+                       'p2<->p2', 'th2' ,NA,
+                       'p3<->p3', 'th3' ,NA,
+                       'p4<->p4', 'th4' ,NA,
+                       'p5<->p5', 'th5' ,NA,
+                       'p6<->p6', 'th6' ,NA,
+                       'F1<->F1',   NA , 1),
+              ncol=3, byrow=T)
> sem.poly.f1<-sem(model.f1, res$correlation, 278)
> summary(sem.poly.f1)

 Model Chisquare =  29.496   Df =  9 Pr(>Chisq) = 0.00053423
 Chisquare (null model) =  514.8   Df =  15
 Goodness-of-fit index =  0.96662
 Adjusted goodness-of-fit index =  0.92212
 RMSEA index =  0.090672   90% CI: (0.055558, 0.12807)
 Bentler-Bonnett NFI =  0.9427
 Tucker-Lewis NNFI =  0.93165
 Bentler CFI =  0.959
 SRMR =  0.039413
 BIC =  -21.152 

 Normalized Residuals
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
-1.6600 -0.3190  0.0354  0.0168  0.4620  1.0100 

 Parameter Estimates
     Estimate Std Error z value Pr(>|z|)             
lam1 0.34134  0.064032   5.3308 9.7803e-08 p1 <--- F1
lam2 0.68875  0.057511  11.9760 0.0000e+00 p2 <--- F1
lam3 0.71250  0.056976  12.5053 0.0000e+00 p3 <--- F1
lam4 0.70180  0.056991  12.3142 0.0000e+00 p4 <--- F1
lam5 0.75545  0.055838  13.5293 0.0000e+00 p5 <--- F1
lam6 0.65687  0.058147  11.2967 0.0000e+00 p6 <--- F1
th1  0.88349  0.077231  11.4396 0.0000e+00 p1 <--> p1
th2  0.52562  0.055189   9.5241 0.0000e+00 p2 <--> p2
th3  0.49234  0.053595   9.1863 0.0000e+00 p3 <--> p3
th4  0.50748  0.053831   9.4273 0.0000e+00 p4 <--> p4
th5  0.42929  0.050581   8.4872 0.0000e+00 p5 <--> p5
th6  0.56852  0.057301   9.9216 0.0000e+00 p6 <--> p6

 Iterations =  11 
> 
> model.f1<-matrix(c(    'F1->p1', 'lam1',NA,
+                        'F1->p2', 'lam2',NA,
+                        'F1->p3', 'lam3',NA,
+                        'F2->p4', 'lam4',NA,
+                        'F2->p5', 'lam5',NA,
+                        'F2->p6', 'lam6',NA,
+                       'p1<->p1', 'th1' ,NA,
+                       'p2<->p2', 'th2' ,NA,
+                       'p3<->p3', 'th3' ,NA,
+                       'p4<->p4', 'th4' ,NA,
+                       'p5<->p5', 'th5' ,NA,
+                       'p6<->p6', 'th6' ,NA,
+                       'F1<->F1',   NA,  1,
+                       'F2<->F2',   NA,  1,
+                       'F2<->F1', 'gam1', NA),
+              ncol=3, byrow=T)
> sem.poly.f1<-sem(model.f1, res$correlation, 278)
> summary(sem.poly.f1)

 Model Chisquare =  17.961   Df =  8 Pr(>Chisq) = 0.021524
 Chisquare (null model) =  514.8   Df =  15
 Goodness-of-fit index =  0.97907
 Adjusted goodness-of-fit index =  0.94505
 RMSEA index =  0.067044   90% CI: (0.02439, 0.10892)
 Bentler-Bonnett NFI =  0.96511
 Tucker-Lewis NNFI =  0.96263
 Bentler CFI =  0.98007
 SRMR =  0.031924
 BIC =  -27.060 

 Normalized Residuals
     Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
-1.44e+00 -1.22e-01  1.75e-05  2.19e-02  3.05e-01  1.33e+00 

 Parameter Estimates
     Estimate Std Error z value Pr(>|z|)             
lam1 0.35667  0.064979   5.4890 4.0421e-08 p1 <--- F1
lam2 0.73069  0.058625  12.4639 0.0000e+00 p2 <--- F1
lam3 0.76292  0.058436  13.0555 0.0000e+00 p3 <--- F1
lam4 0.71051  0.057547  12.3466 0.0000e+00 p4 <--- F2
lam5 0.78826  0.056145  14.0396 0.0000e+00 p5 <--- F2
lam6 0.67030  0.058364  11.4849 0.0000e+00 p6 <--- F2
th1  0.87279  0.077012  11.3331 0.0000e+00 p1 <--> p1
th2  0.46608  0.057072   8.1666 2.2204e-16 p2 <--> p2
th3  0.41796  0.057033   7.3283 2.3315e-13 p3 <--> p3
th4  0.49517  0.054849   9.0279 0.0000e+00 p4 <--> p4
th5  0.37865  0.051814   7.3078 2.7156e-13 p5 <--> p5
th6  0.55069  0.057287   9.6128 0.0000e+00 p6 <--> p6
gam1 0.86705  0.042316  20.4900 0.0000e+00 F1 <--> F2

 Iterations =  14 
> 
> model.f1<-matrix(c(    'F1->p1', 'lam1',NA,
+                        'F1->p2', 'lam2',NA,
+                        'F1->p3', 'lam3',NA,
+                        'F1->p5', 'lam5',NA,
+                        'F2->p1', 'lam6',NA,
+                        'F2->p2', 'lam7',NA,
+                        'F2->p4', 'lam9',NA,
+                        'F2->p6', 'lam10',NA,
+                       'p1<->p1', 'th1' ,NA,
+                       'p2<->p2', 'th2' ,NA,
+                       'p3<->p3', 'th3' ,NA,
+                       'p4<->p4', 'th4' ,NA,
+                       'p5<->p5', 'th5' ,NA,
+                       'p6<->p6', 'th6' ,NA,
+                       'F1<->F1',   NA,  1,
+                       'F2<->F2',   NA,  1),
+              ncol=3, byrow=T)
> sem.poly.f1<-sem(model.f1, res$correlation, 278)
> summary(sem.poly.f1)

 Model Chisquare =  196.44   Df =  7 Pr(>Chisq) = 0
 Chisquare (null model) =  514.8   Df =  15
 Goodness-of-fit index =  0.85094
 Adjusted goodness-of-fit index =  0.55281
 RMSEA index =  0.31257   90% CI: (0.27572, 0.35102)
 Bentler-Bonnett NFI =  0.6184
 Tucker-Lewis NNFI =  0.18776
 Bentler CFI =  0.62096
 SRMR =  0.24622
 BIC =  157.05 

 Normalized Residuals
     Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
-1.45e-05  5.88e-01  2.11e+00  3.11e+00  4.26e+00  9.35e+00 

 Parameter Estimates
      Estimate Std Error z value Pr(>|z|)             
lam1  0.16924  0.091849   1.8426 6.5393e-02 p1 <--- F1
lam2  0.52362  0.083763   6.2512 4.0725e-10 p2 <--- F1
lam3  0.82367  0.078130  10.5422 0.0000e+00 p3 <--- F1
lam5  0.62292  0.070790   8.7995 0.0000e+00 p5 <--- F1
lam6  0.27033  0.102918   2.6267 8.6222e-03 p1 <--- F2
lam7  0.30941  0.083098   3.7234 1.9656e-04 p2 <--- F2
lam9  0.62768  0.089705   6.9972 2.6121e-12 p4 <--- F2
lam10 0.70670  0.095578   7.3940 1.4255e-13 p6 <--- F2
th1   0.85943  0.078044  11.0120 0.0000e+00 p1 <--> p1
th2   0.49249  0.058633   8.3995 0.0000e+00 p2 <--> p2
th3   0.32157  0.104134   3.0880 2.0148e-03 p3 <--> p3
th4   0.60602  0.103772   5.8400 5.2212e-09 p4 <--> p4
th5   0.61197  0.077252   7.9218 2.4425e-15 p5 <--> p5
th6   0.50057  0.121055   4.1351 3.5486e-05 p6 <--> p6

 Iterations =  23 
> 
> # ALGORITHM DOES NOT ALWAYS CONVERGE! COMMON PROBLEM IN SEM - NEED GOOD STARTING VALUES!
> 
> model.f1<-matrix(c(    'F1->p1', 'lam1',NA,
+                        'F1->p2', 'lam2',NA,
+                        'F1->p3', 'lam3',NA,
+                        'F1->p4', 'lam5',NA,
+                        'F1->p5', 'lam6',NA,
+                        'F2->p1', 'lam7',NA,
+                        'F2->p2', 'lam8',NA,
+                        'F2->p3', 'lam9',NA,
+                        'F2->p4', 'lam10',NA,
+                        'F2->p6', 'lam11',NA,
+                       'p1<->p1', 'th1' ,NA,
+                       'p2<->p2', 'th2' ,NA,
+                       'p3<->p3', 'th3' ,NA,
+                       'p4<->p4', 'th4' ,NA,
+                       'p5<->p5', 'th5' ,NA,
+                       'p6<->p6', 'th6' ,NA,
+                       'F1<->F1',   NA,  1,
+                       'F2<->F2',   NA,  1),
+              ncol=3, byrow=T)
> sem.poly.f1<-sem(model.f1, res$correlation, 278)
Warning message:
Optimization may not have converged; nlm return code = 4. Consult ?nlm.
 in: sem.default(ram = ram, S = S, N = N, param.names = pars, var.names = vars,  
> summary(sem.poly.f1)

 Model Chisquare =  106.48   Df =  5 Pr(>Chisq) = 0
 Chisquare (null model) =  514.8   Df =  15
 Goodness-of-fit index =  0.90378
 Adjusted goodness-of-fit index =  0.59589
 RMSEA index =  0.27068   90% CI: (0.22732, 0.31659)
 Bentler-Bonnett NFI =  0.79316
 Tucker-Lewis NNFI =  0.39088
 Bentler CFI =  0.79696
 SRMR =  0.16568
 BIC =  78.341 

 Normalized Residuals
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
-0.0339  1.2000  1.5900  2.1000  2.3900  9.1300 

 Parameter Estimates
      Estimate   Std Error z value  Pr(>|z|)             
lam1    0.012023 0.0083040   1.4479 1.4764e-01 p1 <--- F1
lam2    0.056529 0.0096811   5.8392 5.2466e-09 p2 <--- F1
lam3    0.053156 0.0099656   5.3340 9.6091e-08 p3 <--- F1
lam5    0.067132 0.0097467   6.8877 5.6721e-12 p4 <--- F1
lam6    6.899207 0.2613007  26.4033 0.0000e+00 p5 <--- F1
lam7    0.381239 0.0618228   6.1666 6.9752e-10 p1 <--- F2
lam8    0.629128 0.0562988  11.1748 0.0000e+00 p2 <--- F2
lam9    0.705259 0.0573608  12.2951 0.0000e+00 p3 <--- F2
lam10   0.562415 0.0579267   9.7091 0.0000e+00 p4 <--- F2
lam11   0.342130 0.0797842   4.2882 1.8013e-05 p6 <--- F2
th1     0.842539 0.0759186  11.0979 0.0000e+00 p1 <--> p1
th2     0.508274 0.0623393   8.1534 4.4409e-16 p2 <--> p2
th3     0.402047 0.0629651   6.3852 1.7113e-10 p3 <--> p3
th4     0.580782 0.0640150   9.0726 0.0000e+00 p4 <--> p4
th5   -46.596160 3.5067997 -13.2874 0.0000e+00 p5 <--> p5
th6     0.882978 0.0837961  10.5372 0.0000e+00 p6 <--> p6

 Iterations =  500 
> 
> sem.poly.f1

 Model Chisquare =  106.4792   Df =  5 

        lam1         lam2         lam3         lam5         lam6         lam7 
  0.01202350   0.05652924   0.05315622   0.06713193   6.89920661   0.38123930 
        lam8         lam9        lam10        lam11          th1          th2 
  0.62912813   0.70525906   0.56241481   0.34212982   0.84253875   0.50827437 
         th3          th4          th5          th6 
  0.40204742   0.58078211 -46.59615999   0.88297776 

 Iterations =  500 
> 
> # CAN USE DIFFERENT STARTING VALUES - IF YOU CAN FIND ONES THAT AID CONVERGENCE
> # OR CHANGE MODEL - MAY BE A BAD FIT!
> 
> model.f1<-matrix(c(    'F1->p1', 'lam1',0.012,
+                        'F1->p2', 'lam2',NA,
+                        'F1->p3', 'lam3',NA,
+                        'F1->p4', 'lam5',NA,
+                        'F1->p5', 'lam6',NA,
+                        'F2->p1', 'lam7',0.381,
+                        'F2->p2', 'lam8',0.629,
+                        'F2->p3', 'lam9',0.705,
+                        'F2->p4', 'lam10',0.562,
+                        'F2->p6', 'lam11',0.342,
+                       'p1<->p1', 'th1' ,NA,
+                       'p2<->p2', 'th2' ,NA,
+                       'p3<->p3', 'th3' ,NA,
+                       'p4<->p4', 'th4' ,NA,
+                       'p5<->p5', 'th5' ,NA,
+                       'p6<->p6', 'th6' ,NA,
+                       'F1<->F1',   NA,  1,
+                       'F2<->F2',   NA,  1),
+              ncol=3, byrow=T)
> sem.poly.f1<-sem(model.f1, res$correlation, 278)
Warning message:
Optimization may not have converged; nlm return code = 4. Consult ?nlm.
 in: sem.default(ram = ram, S = S, N = N, param.names = pars, var.names = vars,  
> summary(sem.poly.f1)

 Model Chisquare =  106.48   Df =  5 Pr(>Chisq) = 0
 Chisquare (null model) =  514.8   Df =  15
 Goodness-of-fit index =  0.90376
 Adjusted goodness-of-fit index =  0.59578
 RMSEA index =  0.27068   90% CI: (0.22732, 0.31659)
 Bentler-Bonnett NFI =  0.79316
 Tucker-Lewis NNFI =  0.39088
 Bentler CFI =  0.79696
 SRMR =  0.16568
 BIC =  78.341 

 Normalized Residuals
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
-0.0317  1.2000  1.5900  2.1000  2.3900  9.1300 

 Parameter Estimates
      Estimate   Std Error z value  Pr(>|z|)             
lam1    0.011968 0.0082762   1.4461 1.4816e-01 p1 <--- F1
lam2    0.056329 0.0096471   5.8390 5.2522e-09 p2 <--- F1
lam3    0.052976 0.0099341   5.3327 9.6750e-08 p3 <--- F1
lam5    0.066901 0.0097131   6.8878 5.6679e-12 p4 <--- F1
lam6    6.923472 0.2610195  26.5247 0.0000e+00 p5 <--- F1
lam7    0.381363 0.0618322   6.1677 6.9289e-10 p1 <--- F2
lam8    0.629016 0.0563019  11.1722 0.0000e+00 p2 <--- F2
lam9    0.705404 0.0573691  12.2959 0.0000e+00 p3 <--- F2
lam10   0.562548 0.0579348   9.7100 0.0000e+00 p4 <--- F2
lam11   0.342043 0.0798718   4.2824 1.8489e-05 p6 <--- F2
th1     0.842696 0.0759468  11.0959 0.0000e+00 p1 <--> p1
th2     0.508473 0.0623489   8.1553 4.4409e-16 p2 <--> p2
th3     0.401931 0.0629679   6.3831 1.7353e-10 p3 <--> p3
th4     0.580707 0.0640111   9.0720 0.0000e+00 p4 <--> p4
th5   -46.931763 3.5146401 -13.3532 0.0000e+00 p5 <--> p5
th6     0.882900 0.0838050  10.5352 0.0000e+00 p6 <--> p6

 Iterations =  500 
